﻿using System;

namespace KeyWordSearch.ProcessTree
{
	internal sealed class OperatorShortCuttedOrProcess:NonTerminalNode
	{
		public OperatorShortCuttedOrProcess(NonTerminalNode parent)
			: base(parent)
		{
			if (parent == null)
			{
				throw new ArgumentNullException("parent");
			}
		}



		public override ExecuteResult Execute(KeyWordSearch.Normalization.LiveProgramNormalizationResult inspectionTarget)
		{
			if (this.Childes.Count == 0)
			{
				throw new ProcessInconsistencyException("子ノードが０です");
			}

			Childes.Reset();

			ExecuteResult result = null;

			while (Childes.Next())
			{
				result = Childes.Current.Execute(inspectionTarget);

				if (result.Answer)
				{
					Childes.MoveCurrentToHead();
					break;
				}
			}

			return result;
		}
	}
}
